#!PERL_EXE PERL_FLG
#
use CGI qw(:all);

$q = new CGI;
$| = 1; # piping hot


# INITIALIZE:

# SITE DEPENDANT
$serv_loc        = "AQUA_LOC/Aqua/server/";
$serv_dir        = "AQUA_DIR/Aqua/server/";

$cgi_bin_loc     = "CGI_LOC/Aqua/";
$cgi_bin_dir     = "CGI_DIR/Aqua/";

$tmp_loc         = "TMP_LOC/Aqua/";
$tmp_dir         = "TMP_DIR/Aqua/";

$webmaster       = 'WEBMASTER';


# SITE INDEPENDENT
$author          = "jurgen\@bmrb.wisc.edu";

$overview        = "overview.html";
$logfile         = "server.log";

# PROGRAM SPECIFIC
$icon            = "remover.gif"; # icon



beginning();
remove_temp_dir();
acknowledge_user();
ending();



sub remove_temp_dir{

    if ( defined($ARGV[0]) ) {
	$number_of_last_arguments = $#ARGV;
	if ( $number_of_last_arguments != 0 ) {
	    end_error ("Bad nummer of arguments supplied, exiting");	
	}
    } else {
	end_error ("No arguments supplied, exiting");
    }
    
    $six_random_numbers = $ARGV[0];
    $dir_name = $tmp_dir . $six_random_numbers . "/";
    
    if ( !(-e $dir_name)) {
	end_error ("No such dir: $dir_name");	
    }
        
    end_error ("cannot remove dir: $dir_name exiting")
	if `rm -rf $dir_name`;
}


sub beginning {

    my ( $giffie ) = $serv_loc . "img/$icon";
    
# Just "use" them, so the compiler doesn't warn.
    my ( @dummy ) = ( $serv_loc, $serv_dir, $tmp_loc, $tmp_dir,
			$cgi_bin_loc, $cgi_bin_dir, 
			$overview, $logfile );	
    @dummy = ();
    
    umask 0000; # assists in setting new permissions

    print 
	$q->header('text/html');

    print   
	$q->start_html( -"title"    =>'Cleaning', 
			-"author"   =>$author, 
			-"BGCOLOR"  =>"white"), "\n"; 
    print   
	img {-src=>$giffie,-align=>'RIGHT'};

    print
        "\n", 
	h1( a({href=>$serv_loc},     "Aqua server"       ) ), "\n", 
	br, br, hr;
	
}

sub end_error {
    my ( $message ) = @_;
    print $message, "\n";
    ending();
}

sub ending {
    print   
	hr,
	p("Contact the ", 
	    a({href=>"mailto:".$author}, "author"), "or",
	    a({href=>"mailto:".$webmaster}, "webmaster"), ,
	    "for help, when required."), 
	$q->end_html, "\n";
    exit(0);
}


sub acknowledge_user {
    print   
	p("THANKS"),
	hr, 
	p("Your files have been removed from our server."),
	p("You may go back to the overview of servers\n",
	  "by clicking on the link above."),
	p("Thanks for using the server, hope to see you again.");

    ending();
}
